package com.example.controller;

import com.example.domain.po.Hospital;
import com.example.service.HospitalService;
import com.example.util.PageBean;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @GetMapping("/findByDockerId")
    public Result<Hospital> findByDockerId(Integer dockerId) {
        return Result.success(hospitalService.findByDockerId(dockerId));
    }

    @GetMapping("/list")
    public Result<PageBean<Hospital>> list(Integer pageNum,
                                           Integer pageSize,
                                           String name
    ) {
        return Result.success(hospitalService.list(pageNum, pageSize, name));
    }

    @PostMapping
    public Result<String> add(@RequestBody Hospital hospital) {
        hospitalService.add(hospital);
        return Result.success("添加成功");
    }

    @GetMapping("/del")
    public Result<String> del(Integer id) {
        hospitalService.del(id);
        return Result.success("删除成功");
    }

    @GetMapping("/findAll")
    public Result<List<Hospital>> findAll() {
        return Result.success(hospitalService.findAll());
    }


}
